﻿#include "RS485_Wind_Direction_Transmitter_V2.h"
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

RS485_Wind_Direction_Transmitter_V2 windDirection;


uint8_t  Address = 2;

const char* Orientation[17] = {
  "北", "东北偏北", "东北", "东北偏东", "东", "东南偏东", "东南", "东南偏南", "南",
  "西南偏南", "西南", "西南偏西", "西", "西北偏西", "西北", "西北偏北", "北"
};

void setup()
{
  Serial.begin(115200);
  mySerial.begin(9600);
  windDirection.begin(mySerial);
  windDirection.SetSlaveAddress(/*Current modbus slave address*/0x00, /*Revised address*/0x03);

  Address = windDirection.GetSlaveAddress(); 
  Serial.println(Address); 
}

void loop()
{
  //获取16方位风向
  int Direction = windDirection.GetWindDirection(/*modbus从机的地址*/Address);
  //获取360°风向
  float Angle = windDirection.GetWindAngle(/*modbus从机的地址*/Address);
  Serial.println(Address);
  Serial.println(Orientation[Direction]);
  Serial.print(Angle); Serial.println("°");
  Serial.println();
  delay(500);
}